class Dish:
  def __init__(self, d_name, price, stock):
    self.__d_name = d_name
    self.price = price
    self.stock = stock

  def get_d_name(self):
    return self.__d_name

  def display(self):
    print(f"菜品名称“{self.get_d_name()}”，售价{self.price}，库存{self.stock}")


class Customer:
  def __init__(self, name):
    self.__name = name
    self.sum_price = 0
    self.order = {}

  def get_name(self):
    return self.__name

  def display(self):
    print(f"顾客姓名：{self.get_name()}，订单信息为：")
    for dish, num in self.order.items():
      print(f"菜品：{dish}，数量{num}")


# 点菜系统类
class OrderManage:
  def __init__(self):
    self.dish_list = []
    self.customer_list = []

  def add_dish(self, dish):
    for i in self.dish_list:
      if i.get_d_name() == dish.get_d_name():
        print("已经有这道菜了！！")
        return
      else:
        continue
    self.dish_list.append(dish)
    return

  def remove_dish(self, del_dish_name):
    for i in self.dish_list:
      if i.get_d_name() == del_dish_name:
        self.dish_list.remove(i)
        return
    print("没有这道菜！")

  def show_all_dishes(self):
    for i in self.dish_list:
      print(f"{i.get_d_name()}，价格：{i.price}，库存：{i.stock}")
    return

#————————————————————————————————————————————————————————
# 添加顾客
  def add_customer(self, customer):
    for i in self.customer_list:
      if i.get_name() == customer.get_name():
        print("已经有该顾客了！！")
        return
      else:
        continue
    self.customer_list.append(customer)
    return


# ————————————————————————————————————————————————————————

  def customer_make_order(self, customer, dish_name, dish_num):
    """
    点菜
    :param customer: 顾客
    :param dish_name: 菜名
    :param dish_num: 点菜数量
    """
    for d in self.dish_list:
      if d.get_d_name() == dish_name:
        if d.stock >= dish_num:
          new_order = {dish_name: dish_num}
          customer.order.update(new_order)
          d.stock -= dish_num
          print("点菜成功！")
          return
        else:
          print("菜品库存不足！")
          return
      else:
        continue
    print("没有这道菜！")
    return

  # 结账
  def cal_price(self, customer):
    """
    计算总价
    :return: 账单计算结果
    """
    for dish, num in customer.order.items():
      for dl in self.dish_list:
        if dish == dl.get_d_name():
          customer.sum_price += dl.price * num
        else:
          continue
    return customer.sum_price
    #
    # return

  def show_order_list(self):
    for i in self.customer_list:
      if i.order:
        i.display()
        return
      else:
        continue
    return


if __name__ == '__main__':
    # 创建菜品对象
    dish1 = Dish("宫保鸡丁", 39, 10)
    dish2 = Dish("鱼香肉丝", 28, 8)
    dish3 = Dish("麻婆豆腐", 17, 15)
    dish4 = Dish("四喜丸子", 58, 4)

    dishes = [dish1, dish2, dish3, dish4]

    # 创建客人对象
    customer1 = Customer("王红")
    customer2 = Customer("李明")
    customer3 = Customer("周强")

    customers = [customer1, customer2, customer3]

    # 创建点菜系统对象
    om = OrderManage()
    for d in dishes:
      om.add_dish(d)

    for c in customers:
      om.add_customer(c)

    print("————————————————————————————————————")
    print("菜单如下：")
    om.show_all_dishes()
    print("————————————————————————————————————")

    # 删除菜品
    print("现在删除菜品：")
    print(f"即将删除{dish2.get_d_name()}")
    om.remove_dish(dish2.get_d_name())
    print(f"删除{dish2.get_d_name()}后的菜单：")
    om.show_all_dishes()
    print("————————————————————————————————————")

    # 客人点菜
    print("客人开始点菜：")
    om.customer_make_order(customer1, "麻婆豆腐", 1)
    om.customer_make_order(customer1, "四喜丸子", 2)
    print(f"顾客{customer1.get_name()}订单如下：")
    customer1.display()
    print("————————————————————————————————————")

    om.show_all_dishes()
    print("————————————————————————————————————")
    # 展示全部订单
    om.show_order_list()

    print("————————————————————————————————————")
    # 结账
    print(f"为{customer1.get_name()}结账：")
    print(f"总计{om.cal_price(customer1)}元")
















